﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AssertExtensions.cs" company="">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System;

namespace Photon.Testing
{
    /// <summary>
    /// Provides additional assert methods
    /// </summary>
    public static class AssertExtensions
    {
        public static void BecomesTrue(Func<bool> condition, TimeSpan timeout, string message, params object[] args)
        {
            var dateTime = DateTime.Now;
            while (true)
            {
                if (condition())
                {
                    return;
                }

                if (DateTime.Now - dateTime > timeout)
                {
                    Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Fail(message, args);
                }
            }
        }

        public static void BecomesTrue(Func<bool> condition, TimeSpan timeout)
        {
            BecomesTrue(condition, timeout, "Assert failed.");
        }
    }
}
